package com.jp.knowledge.my.activity;

import com.google.gson.JsonObject;
import com.jiayen.util.ToasUtil;
import com.jp.knowledge.R;
import com.jp.knowledge.http.HttpHelper;
import com.jp.knowledge.model.UserData;
import com.jp.knowledge.my.resources.OrganizeJoinRes;

/**
 * Created by 528787067@qq.com on 2016/12/29.
 */

public class DepartmentRenameActivity extends DepartmentCreateActivity {

    UserData userData;

    @Override
    protected void init() {
        super.init();
        userData = application.getUserData();
        requestCode = userData.getOrganizaType() - 1;

        if(requestCode == OrganizeJoinRes.SCHOOL_INDEX) {
            topName.setText("修改院系名称");
            editText.setHint("编辑院系名称");
        } else {
            topName.setText("修改部门名称");
            editText.setHint("编辑部门名称");
        }
        String departName = intent.getStringExtra(OrganizeJoinRes.TITLE);
        if (departName == null)
            departName = "";
        editText.setText(departName);
        editText.setSelection(departName.length());
    }

    @Override
    protected void editFinishBnClick() {
        if(editText.getText().toString().trim().length() == 0){
            ToasUtil.toast(this, R.string.toast_department_create_params_remind);
        } else{
            loading.show();
            JsonObject param = new JsonObject();
            param.addProperty("token", HttpHelper.token);
            param.addProperty("organizaId", userData.getCompanyId());
            param.addProperty("depaId", intent.getStringExtra(OrganizeJoinRes.DEPA_ID));
            param.addProperty("type", requestCode + 1);
            param.addProperty("name", editText.getText().toString());
            HttpHelper.getInstance(this).renameDepartment(param, requestCode, this);
        }
    }
}
